(require :uffi)

(defpackage :mktemp
  (:use :cl :uffi)
  (:export #:mktemp
	   #:temprary-filename))

(in-package :mktemp)

(def-function ("mktemp" c-mktemp)
    ((template :cstring))
  :returning :cstring
  :module "c")

(defun mktemp ()
  "Return a temporary file name. This is a random-looking name that
   is guaranteed not to have existed when this function was called."
  (with-cstring (template-cstring "lisp-temp-XXXXXX")
    (convert-from-cstring (c-mktemp template-cstring))))

(defun temporary-filename ()
  "Return a temporary file name. This is a random-looking name that
   is guaranteed not to have existed when this function was called.
   This is just an alias for mktemp."
  (mktemp))

(proclaim '(inline temporary-filename))